package demo05_Prototype;

import demo05_Prototype.model.*;

/**
 * 设计并实现一个客户类Customer，其中包含一个名为客户地址的成员变量，客户地址的类
 * 型为Address，用浅克隆和深克隆分别实现Customer对象的复制并比较这两种克隆方式的
 * 异同。
 */
public class Prototype01 {

    public static void main(String[] args) throws CloneNotSupportedException {

        System.out.println("------浅拷贝-----");

        CustomerShallowCopy customer1 = new CustomerShallowCopy("张三",255,170.1,new AddressShallowClone("广州市"));
        CustomerShallowCopy customer2 = (CustomerShallowCopy) customer1.clone();
        customer2.setName("哈哈");
        customer2.setAge(15);
        customer2.setHeight(180);
        customer2.getAddress().setAdressName("汕头");
        System.out.println(customer1);
        System.out.println(customer2);


        System.out.println("------实现clone接口的方式深拷贝-----");

        CustomerDeepClone01 customer3 = new CustomerDeepClone01("张三",255,170.1,new AddressDeepClone01("广州市"));
        CustomerDeepClone01 customer4 = (CustomerDeepClone01) customer3.clone();
        customer4.setName("哈哈");
        customer4.setAge(15);
        customer4.setHeight(180);
        customer4.getAddress().setAdressName("汕头");
        System.out.println(customer3);
        System.out.println(customer4);


        System.out.println("------实现序列化接口的方式深拷贝-----");

        CustomerDeepClone02 customer5 = new CustomerDeepClone02("张三",255,170.1,new AddressDeepClone02("广州市"));
        CustomerDeepClone02 customer6 = (CustomerDeepClone02) customer5.clone();
        customer6.setName("哈哈");
        customer6.setAge(15);
        customer6.setHeight(180);
        customer6.getAddress().setAdressName("汕头");
        System.out.println(customer5);
        System.out.println(customer6);
    }
}
